package com.lanou.pianke.login.web.controller;

import com.lanou.pianke.login.entity.TokenUser;
import com.lanou.pianke.login.entity.User;
import com.lanou.pianke.login.service.impl.LoginServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpSession;


@RestController
@RequestMapping("/user")
public class LoginController {

    @Autowired
    private LoginServiceImpl loginService;


    @PostMapping("/login")
    public String userLogin(String username, String password, HttpSession session){

        User user = new User(username,password);

        String token = loginService.login(user);

        if (token!=null){
            return token;
        }else {
            return null;
        }

    }

    @GetMapping("/token")
    public User getUserByToken(String token){

        User user = loginService.getUserByToken(token);
        System.out.println(user);
        if (user != null){
            return user;
        }else {
            return null;
        }
    }
}
